/*
 * Hidden Equity LLC
 * Author: Maksym Fedyay, Kyiv, mcsimf@gmail.com
 * Date: 29.02.2012
 */

package com.hiddenequity.servicedaccountservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.hiddenequity.utils.XMLUtils;

public class ServicedAccountServiceParser {

	
	Document _XMLDocument;
	
	
	/*
	 * Constructor
	 */
	public ServicedAccountServiceParser(String XMLData){
		try {
			_XMLDocument = XMLUtils.XMLStringToDoc(XMLData);
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
	}//Constructor

	
	
	/*
	 * Check response for errors
	 */
	public String checkForErrors(){
		String error = null;
		try {
	        NodeList faultstring = _XMLDocument.getElementsByTagName("faultstring");
	        error =  XMLUtils.getCharacterDataFromElement((Element) faultstring.item(0));
	    }
	    catch (Exception e) {
	    	e.printStackTrace();
	    }
		return error;
	}//checkForErrors
	
	
	public String getCustomerId(){
		ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
		String Id = null;
		try {	
			NodeList nodes = _XMLDocument.getElementsByTagName("customerId");
			
			Id = XMLUtils.getCharacterDataFromElement((Element) nodes.item(0));
			
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
		return Id;
	}
	
	
}
